package com.yztc.yidoutang.fragment.danpin_fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yztc.yidoutang.R;
import com.yztc.yidoutang.adapter.DanPinAdapter;
import com.yztc.yidoutang.bean.SharingsBean;
import com.yztc.yidoutang.utils.SpacesItemDecoration;

import java.util.List;

/**
 * Created by My on 2016/10/18.
 */

public class DanPinFragment extends Fragment implements DanPinContract.View {
    private String queryWords = "";
    private RecyclerView mRecyclerView;
    private DanPinContract.Presenter presenter = new DanPinPresenter(this);

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_pic, null);
        mRecyclerView = (RecyclerView) view.findViewById(R.id.pic_rv);
        initView();
        return view;
    }

    public void initView() {
        Bundle bundle=getArguments();
        queryWords=bundle.getString("queryWords");
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,
                StaggeredGridLayoutManager.VERTICAL));
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        SpacesItemDecoration decoration = new SpacesItemDecoration(10);
        mRecyclerView.addItemDecoration(decoration);
        getDRData();
    }

    @Override
    public void getDRData() {
        presenter.getDPData(queryWords);
    }

    @Override
    public void GetDPDataSuccess(List<SharingsBean> listBeen) {
        DanPinAdapter adapter=new DanPinAdapter(listBeen,getActivity());
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    public void GetDPDataFail(String msg) {

    }
}
